package org.jspar;

import org.jspar.matrix.IMatrixBuilder;
import org.jspar.matrix.MatrixType;
import org.jspar.matrix.UnsignedMatrixBuilder;
import org.jspar.partition.DummyRule;
import org.jspar.partition.PartitionRule;
import org.jspar.partition.RentLikeRule;
import org.jspar.partition.SizeBasedRule;
import org.jspar.partition.SlopeBasedRule;
import org.jspar.partition.SlopeRatioRule;
import org.xteam.commandline.Option;

public class Options {
	
	private static final int CC_SEARCH_LEVEL = 2;

	private static final int DEF_PARTITION_RULE = PartitionRule.DUMMY;

	private static final int MAX_PARTITION_SIZE = 4;

	private static final int MAX_PARTITION_CONN = 24;

	private static final float DEF_PARTITION_RATIO = 3.0f;

	@Option(name="d", help="qualifier, sets the debug level")
	public int debug_level = 11;
	
	@Option(name="n", help="qualifier, inhibits routing")
	public boolean do_routing = true;
	
	@Option(name="x", help="flag; modified PostScript header")
	public boolean latex = false;
	
	@Option(name="m", help="qualifier, sets signal-flow style")
	public int matrix_type = MatrixType.UNSIGNED;
	
	@Option(name="l", help="qualifier, limits cc search")
	public int ccSearchLevel = CC_SEARCH_LEVEL;
	
	@Option(name="p", help="qualifier, used for clustering")
	public int partition_rule =  DEF_PARTITION_RULE;
	
	@Option(name="s", help="qualifier, used for clustering")
	public int maxPartitionSize =  MAX_PARTITION_SIZE;
	
	@Option(name="c", help="qualifier, used for clustering")
	public int maxPartitionConn =  MAX_PARTITION_CONN;
	
	@Option(name="r", help="qualifier, used for clustering")
	public float partitionRatio = DEF_PARTITION_RATIO;
	
	@Option(name="f", help="flag; terminates GR early")
	public boolean stopAtFirstCut = false;
	
	@Option(name="v", help="flag; removes sliVer corrections")
	public boolean useSlivering = true;
	
	@Option(name="w", help="flag; turns Weighted averaging on")
	public boolean useAveraging = false;
	
	@Option(name="b", help="flag (use XCanvas scaling)")
	public boolean Xcanvas_scaling = false;
	
	@Option(name="a", help="flag, in parsing - compute aspect ratios")
	public boolean computeAspectRatios = false;
	
	@Option(name="h", help="flag; do hand placement")
	public boolean do_hand_placement = false;
	
	@Option(name="i", help="flag; excludes system terminals")
	public boolean includeSysterms = false;
	
	@Option(name="g", help="qualifier; used for conGestion")
	public int congestionRule = 2;

	public IMatrixBuilder getMatrixBuilder() {
		if (matrix_type == MatrixType.UNSIGNED)
			return new UnsignedMatrixBuilder();
		throw new RuntimeException("getMatrixBuilder not complete");
	}

	public PartitionRule getPartitionRule() {
		if (partition_rule == PartitionRule.DUMMY)
			return new DummyRule(this);
		if (partition_rule == PartitionRule.SIZE_BASE)
			return new SizeBasedRule(this);
		if (partition_rule == PartitionRule.RENT_LIKE)
			return new RentLikeRule(this);
		if (partition_rule == PartitionRule.SIZE_BASE)
			return new SizeBasedRule(this);
		if (partition_rule == PartitionRule.SLOPE_BASE)
			return new SlopeBasedRule(this);
		if (partition_rule == PartitionRule.SLOPE_RATIO)
			return new SlopeRatioRule(this);
		return null;
	}
	
	private static Options instance = new Options();

	public static Options getDefault() {
		return instance;
	}

}
